package com.meme.editor.property;


import javax.swing.JComponent;

import org.apache.log4j.Logger;

import com.meme.editor.gui.PropertyEditPanel;

public abstract class PropertyControl 
{
	static Logger logger = Logger.getLogger (PropertyControl.class);
	
	PropertyValue mPropertyValue;
		
	protected PropertyValue getPropetyValue ()
	{
		return mPropertyValue;
	}
	
	protected void setPropertyValue (PropertyValue value)
	{	
		mPropertyValue = value;
	}
	
	protected void updatePropertyValue ()
	{
		getPropetyValue().updateFromControl( makeDataForValue ());
	}
	
	public boolean isEditable ()
	{
		return getPropetyValue().isEditable();
	}
	
	public abstract void enableEvents ();
	public abstract void disableEvents ();
	
	/**
	 * update from the params passed by PropertyValue
	 * @param controlParams
	 */
	public void updateFromValue (Object[] controlParams) {}
	
	/**
	 * For PropertyValue doesn't know what control this is,
	 * so pls update selfly.
	 */
	public void updateFromValue () {}
	
	public void updateFromValue (Object controlParam)
	{
		updateFromValue (new Object[] {controlParam});
	}
	
	/**
	 * return the current status to PropertyValue
	 * @return
	 */
	public abstract Object[] makeDataForValue ();
	
	//public abstract void setEditable (boolean bEditable);
	

	
	public abstract JComponent getComponent ();
	
	public abstract void disposeComponent ();
	
	protected abstract boolean _setParameter (String key, Object param);

	
	//public void notifyValueChanged (Object newValue); // as a listener
	
	public int getGridHeight ()
	{
		return 1; // default
	}
	

}
